home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / xmsif.exe / XMSTEST3.C < prev   
C/C++ Source or Header  |  1991-12-08  |  23KB  |  607 lines

  1. /***************************************************************************
  2. *   xmstest3.c                                                             *
  3. *   MODULE:  XMSIF                                                         *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.0                                                           *
  6. *   DATE:    12/08/91                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires xmsif.h, testutil.h, and xmstest.h to compile.                *
  11. *   Compiles under Borland C++ 2.0, Turbo C 2.0, or MSC 6.00A.             *
  12. *                                                                          *
  13. *   Regression test and example for XMSIF. See XMSTEST.C for more detail.  *
  14. *                                                                          *
  15. ***************************************************************************/
  16.  
  17. /*
  18. ** system includes <>
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25.  
  26. /*
  27. ** custom includes ""
  28. */
  29.  
  30. #include "xmsif.h"
  31. #include "xmstest.h"
  32.  
  33. #include "testutil.h"
  34.  
  35.  
  36. /*
  37. ** local #defines
  38. */
  39.  
  40. /*
  41. ** misc: copyright strings, version macros, etc.
  42. */
  43.  
  44. /*
  45. ** typedefs
  46. */
  47.  
  48. /*
  49. ** global variables
  50. */
  51.  
  52. extern int testno;
  53. extern char *gblmsg;
  54.  
  55.  
  56. /*
  57. ** static globals
  58. */
  59.  
  60. /*
  61. ** function prototypes
  62. */
  63.  
  64. /*
  65. ** functions
  66. */
  67.  
  68.  
  69. /***************************************************************************
  70. *   FUNCTION: DO_UMB_TESTS                                                 *
  71. *                                                                          *
  72. *   DESCRIPTION:                                                           *
  73. *                                                                          *
  74. *       Does UMB tests.                                                    *
  75. *                                                                          *
  76. *   ENTRY:                                                                 *
  77. *                                                                          *
  78. *       None.                                                              *
  79. *                                                                          *
  80. *   EXIT:                                                                  *
  81. *                                                                          *
  82. *       Void.                                                              *
  83. *                                                                          *
  84. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  85. *                                                                          *
  86. ***************************************************************************/
  87. void do_UMB_tests(void)
  88. {
  89.     unsigned long largest, allsize;
  90.     unsigned long allsize2;
  91.     unsigned long finalsize;
  92.     void far *handle;
  93.     int status;
  94.     int haveUMB = 0;
  95.     int goodallcore = 1;
  96.  
  97.     gblmsg = "  UMB TESTS";
  98.  
  99.     /* are there UMBs in this system? */
  100.     TESTHEADER();
  101.     printf("Testing UMBcoreleft() and UMBallcoreleft(), determining whether\n");
  102.     printf("there are UMBs in this system.\n");
  103.     largest = UMBcoreleft();
  104.     weirdcodechk("UMBcoreleft()", 0, (void far *) NULL, 0, 0);
  105.     allsize = UMBallcoreleft();
  106.     if (_XMMerror != 0)
  107.     {
  108.         printf("UMBallcoreleft() returned unexpected code 0x%X\n",
  109.                                                      (unsigned int) _XMMerror);
  110.         printf("Another broken system. *sigh*.\n");
  111.         printf("Values returned by UMBallcoreleft() are junk.\n");
  112.         allsize = ((largest == 0L) ? 0L : (384L * 1024L));
  113.         goodallcore = 0;
  114.     }
  115.     if ((largest == 0L) && (allsize == 0L))
  116.     {
  117.         printf("No UMBs found.\n");
  118.     }
  119.     else
  120.     {
  121.         haveUMB = 1;
  122.     }
  123.     if (allsize < largest)
  124.     {
  125.         printf("UMBallcoreleft() reports total size smaller than size of\n");
  126.         printf("largest UMB (from UMBcoreleft()).\n");
  127.         exit(3);
  128.     }
  129.     /* the theoretical max on UMBs is 384K (1024K - 640K) */
  130.     if (((allsize & 0xF) != 0L) || (allsize > (384L * 1024L)))
  131.     {
  132.         printf("UMBallcoreleft() returned weird value %lu\n", allsize);
  133.         exit(3);
  134.     }
  135.     else if (goodallcore != 0)
  136.     {
  137.         printf("UMBallcoreleft() reports %lu bytes in UMBs.\n", allsize);
  138.     }
  139.     if (((largest & 0xF) != 0L) || (largest > (384L * 1024L)))
  140.     {
  141.         printf("UMBcoreleft() returned weird value %lu\n", largest);
  142.         exit(3);
  143.     }
  144.     else
  145.     {
  146.         printf("UMBcoreleft() reports largest UMB is %lu bytes.\n", largest);
  147.     }
  148.     TESTTAILER();
  149.  
  150.     /* try allocating a UMB */
  151.     TESTHEADER();
  152.     printf("Testing UMBalloc().\nShould %s.\n",
  153.                                         ((haveUMB == 0) ? "fail" : "succeed"));
  154.     handle = UMBalloc(((haveUMB == 0) ? (largest) : (largest - 1)), &finalsize);
  155.     weirdcodechk("UMBalloc()", 0, (void far *) NULL, 0, 0);
  156.     if (handle == (void far *) NULL)
  157.     {
  158.         if (haveUMB != 0)
  159.         {
  160.             printf("UMBalloc() returned NULL.\n");
  161.             exit(3);
  162.         }
  163.     }
  164.     else
  165.     {
  166.         if (haveUMB == 0)
  167.         {
  168.             printf("UMBalloc() didn't return NULL.\n");
  169.             exit(3);
  170.         }
  171.     }
  172.     if (finalsize != largest)
  173.     {
  174.         printf("Size rounding didn't happen.\n");
  175.         UMBfree(handle);
  176.         exit(3);
  177.     }
  178.     if (goodallcore != 0)
  179.     {
  180.         allsize2 = UMBallcoreleft();
  181.         weirdcodechk("UMBallcoreleft()", 0, (void far *) NULL, 0, 0);
  182.         if (allsize2 != (allsize - finalsize))
  183.         {
  184.             printf("Total dropped weirdly from %lu to %lu\n", allsize,
  185.                                                                      allsize2);
  186.             UMBfree(handle);
  187.             exit(3);
  188.         }
  189.     }
  190.     TESTTAILER();
  191.  
  192.     /* free it */
  193.     if (haveUMB != 0)
  194.     {
  195.         TESTHEADER();
  196.         printf("Testing UMBfree().\nShould succeed.\n");
  197.         status = UMBfree(handle);
  198.         TRIPLECHECK("UMBfree()", status, 0, (void far *) NULL, 0, 0);
  199.         if (goodallcore != 0)
  200.         {
  201.             allsize2 = UMBallcoreleft();
  202.             weirdcodechk("UMBallcoreleft()", 0, (void far *) NULL, 0, 0);
  203.             if (allsize2 != allsize)
  204.             {
  205.                 printf(
  206.                   "Total before UMBalloc(): %lu  Total after UMBfree(): %lu\n",
  207.                   allsize, allsize2);
  208.                 exit(3);
  209.             }
  210.         }
  211.     }
  212.  
  213.     return;
  214. } /* end of do_UMB_tests() */
  215.  
  216.  
  217. /***************************************************************************
  218. *   FUNCTION: DO_ICOPY_TESTS                                               *
  219. *                                                                          *
  220. *   DESCRIPTION:                                                           *
  221. *                                                                          *
  222. *       Tests interval copy functions (_XMMicopy() and macros).            *
  223. *                                                                          *
  224. *   ENTRY:                                                                 *
  225. *                                                                          *
  226. *       None.                                                              *
  227. *                                                                          *
  228. *   EXIT:                                                                  *
  229. *                                                                          *
  230. *       Void.                                                              *
  231. *                                                                          *
  232. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  233. *